function header(map) {
    var arr = [];
    arr.push("package " + map.attach.beanPackage + ";");
    arr.push('');
    arr.push('');
    arr.push("import io.swagger.v3.oas.annotations.media.Schema;");
    arr.push("import javax.validation.constraints.Size;");
    arr.push('');
    arr.push("import javax.validation.constraints.NotNull;");
    arr.push("import java.io.Serializable;");
    arr.push('');
    arr.push('');
    arr.push('/**');
    arr.push(' * POJO');
    arr.push(' * ' + map.tableComment + ' [' + map.tableName + ']');
    arr.push(' * @author ChenSS on 2018/6/20.');
    arr.push(' */');
    arr.push('@Schema(description = "' + map.tableComment + ' [' + map.tableName + '] 实体类")');
    arr.push('public class ' + map.pascalName + ' implements Serializable {');
    arr.push('');
    return arr.join("\r\n");
}

function field(map) {
    var arr = [];
    var columns = map.columns;
    for (var i = 0; i < columns.length; i++) {
        var column = columns[i];
        arr.push('');
        arr.push('    /**');
        arr.push('     * ' + column.columnComment);
        arr.push('     */');
        if (column.nullable === false && column.camelName !== 'id') {
            arr.push('    @NotNull');
        }
        if (column.javaType === 'String') {
            arr.push('    @Size(max = ' + column.length + ')');
        }
        if (column.javaType === 'Double' || column.javaType === 'BigDecimal') {
            arr.push('    @Digits(integer = ' + column.numericPrecision + ', fraction = ' + column.numericScale + ')');
        }
        arr.push('    @Schema(description = "' + column.columnComment + '")');
        if (column.javaType === 'Long' && column.camelName === 'id') {
            arr.push('    @JsonFormat(shape = JsonFormat.Shape.STRING)');
        }
        arr.push('    private ' + column.javaType + ' ' + column.camelName + ';');
        arr.push('');
    }
    return arr.join("\r\n");
}

function methods(map) {
    var arr = [];
    var columns = map.columns;
    for (var i = 0; i < columns.length; i++) {
        var column = columns[i];
        arr.push('');
        arr.push('    public ' + column.javaType + ' get' + column.pascalName + '() {');
        arr.push('        return ' + column.camelName + ';');
        arr.push('    }');
        arr.push('');
        arr.push('    public void set' + column.pascalName + '(' + column.javaType + ' ' + column.camelName + ') {');
        arr.push('        this.' + column.camelName + ' = ' + column.camelName + ';');
        arr.push('    }');
        arr.push('');
    }
    return arr.join("\r\n");
}

function footer(map) {
    return "}\r\n";
}

function main(map) {
    var arr = [];
    arr.push(header(map));
    arr.push(field(map));
    arr.push(methods(map));
    arr.push(footer(map));
    return arr.join('');
}

export default main;